clear*
set maxvar 11000

global date _2025_10_28
cd "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Estimations/"

***********************************************************************************************************
********************************** Figure 1: Subnational poverty, inequality and temperature in Indonesia
***********************************************************************************************************

use "${date}/_data/spid_for_analysis_v2.dta", clear

collapse (mean) poor215 gini temp, by(geo_code2_new)

spshape2dta "/Users/atri0032/Dropbox/World Bank/Temperature, poverty, and inequality/Shapefile/am24_subnat_em.shp", saving("worldmap") replace

gen geo_code = geo_code2_new
replace geo_code = subinstr(geo_code,"ADM1","GAUL1",.)

sort geo_code
	merge 1:m geo_code using "worldmap.dta", force
		drop _merge
		drop if _ID==.
		
format poor215 %12.0fc
format gini %12.0fc
	
xtset, clear			
spset, modify shpfile("worldmap_shp.dta")

// Poverty
colorpalette viridis, n(12) nograph reverse
local colors `r(p)'
grmap poor215 if code=="IDN", fcolor(`r(p)') ocolor(white ..) osize(0.05 ..) legstyle(2) ///
		 legend(label(1 "No data") label(2 "Below 2") label(3 "2-5") label(4 "5-7") ///
		 label(5 "7+") size(vsmall) pos(8) region(fcolor(white))) title("Poverty", size(medium)) 
graph export "${date}/_figures/_fig_1a.pdf", as(pdf) replace	
	
// Inequality
colorpalette HCL blues, n(12) nograph reverse
local colors `r(p)'
grmap gini if code=="IDN", fcolor(`r(p)') ocolor(white ..) osize(0.05 ..) legstyle(2) ///
		 legend(label(1 "No data") label(2 "Below 34") label(3 "34-35") label(4 "35-38") ///
		 label(5 "38+") size(small) pos(8) region(fcolor(white))) title(Inequality, size(medium)) 
graph export "${date}/_figures/_fig_1b.pdf", as(pdf) replace	

// Temperature
colorpalette HSV heat, n(6) nograph reverse
local colors `r(p)'	 
grmap temp if code=="IDN", fcolor(`r(p)') ocolor(white ..) osize(0.05 ..) legstyle(2) ///
		 legend(label(1 "No data") label(2 "Below 20") label(3 "20-21") label(4 "21-22") ///
		 label(5 "22+") size(small) pos(8) region(fcolor(white))) title(Temperature, size(medium))	 
graph export "${date}/_figures/_fig_1c.pdf", as(pdf) replace	
